<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page import="com.db.conn"%>
<%@ page import="java.sql.*"%>
<%@ page import="com.db.Pagination"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<script src="<%=path %>/admin/js/jquery.js" type="text/javascript"></script>
<script src="<%=path %>/admin/js/formValidator.js" type="text/javascript"></script>  
<script src="<%=path %>/admin/js/formValidatorRegex.js" type="text/javascript"></script>
<link href="<%=path %>/admin/css/validator.css" rel="stylesheet" type="text/css" />



<jsp:include flush="true" page="${basePath}/admin/head.jsp"></jsp:include>

 <div class="panel panel-primary">
            <div class="panel-heading">
                <h3 class="panel-title">添加房间信息</h3>
            </div>
            <div class="panel-body" style="min-height: 500px;">
           <table style="width:100%;"><tr><td align="center">
          		<form  action="<%=path %>/rooms_Add?id=<%=request.getParameter("id")%>" method="post">

					  <table  style="width:98%;margin-left:10px;" align="center">
                    <tbody>
                    <tr>
<td  style=" text-align:right; width:20%;"><font style='color:red'>*&nbsp;</font>房间编号:</td>
<td class="tbright"><div style="display:inline;float:left;">
<input name="txt_rno" type="text" id="txt_rno" style="width: 200px; " /></div><div id="txt_rnoTip" style="width:250px;display:inline;float:left;text-align:left;"></div>
 </td></tr>



<tr>
<td  style=" text-align:right; width:20%;"><font style='color:red'>*&nbsp;</font>楼层:</td>
<td class="tbright"><div style="display:inline;float:left;">
<input name="txt_floor" type="text" id="txt_floor" style="width: 200px; " /></div><div id="txt_floorTip" style="width:250px;display:inline;float:left;text-align:left;"></div>
 </td></tr>

<tr>
<td  style=" text-align:right; width:20%;"><font style='color:red'>*&nbsp;</font>朝向:</td>
<td class="tbright"><div style="display:inline;float:left;">
<input name="txt_directions" type="text" id="txt_directions" style="width: 200px; " /></div><div id="txt_directionsTip" style="width:250px;display:inline;float:left;text-align:left;"></div>
 </td></tr>



    <tr>
        <td>&nbsp;</td>
        <td align="left">
        <input type="submit" name="btnAdd" value="添 加" onclick="return jQuery.formValidator.PageIsValid('1');" id="btnAdd"   class="btn btn-info" />
    <input name="btnReturn" type="button" value="返 回" class="btn btn-info"  onclick="location.href='<%=path %>/admin/roomtype/roomtype_Manage.jsp';"  />
    
               </td>
    </tr>
                    </tbody>
                </table>
			
    </form>

               <%
                   //定义四个分页会用到的变量
                   int pageSize=15;
                   int pageNow=1;//默认显示第一页
                   int rowCount=0;//该值从数据库中查询
                   int pageCount=0;//该值是通过pageSize和rowCount
//接受用户希望显示的页数（pageNow）
                   String s_pageNow=request.getParameter("pageNum");
                   if(s_pageNow!=null){
//接收到了pageNow
                       pageNow=Integer.parseInt(s_pageNow);
                   }

                   String where="  tid= "+request.getParameter("id");
                   if(request.getParameter("txt_rno")!=null)
                   {
                       where+=" and rno like '%"+request.getParameter("txt_rno")+"%' ";
                   }


                   conn cn=new conn();


                   ResultSet rs=cn.query("select count(*) from rooms a where "+where);
                   if(rs.next()){
                       rowCount=rs.getInt(1);
                   }

//计算pageCount
                   if(rowCount%pageSize==0){
                       pageCount=rowCount/pageSize;
                   }else{
                       pageCount=rowCount/pageSize+1;
                   }
//查询出需要显示的记录

                   rs=cn.query("select  * from rooms a where "+where+" order by rno desc limit "+pageSize*(pageNow-1)+", "+pageSize);

               %>

               <table cellspacing="0" border="0" style="width:100%;border-collapse:collapse;"  >
                   <tr>
                       <th >房间编号</th>

                       <th >楼层</th>
                       <th >朝向</th>
                       <th scope="col">操作</th>		</tr>
                   <%
                       while(rs.next()){
                   %>
                   <tr align="center" >
                       <td><%=rs.getString("rno") %></td>

                       <td><%=rs.getString("floor") %></td>
                       <td><%=rs.getString("directions") %></td>
                       <td >
                           <a href="<%=path %>/admin/rooms/rooms_Edit.jsp?id=<%=rs.getString("rno") %>">编辑</a>&nbsp;
                           <a href="<%=path %>/rooms_Delete?id=<%=rs.getString("rno") %>">删除</a>
                   </tr>
                   <%} %>

               </table>
               <table width=100%>
                   <tbody>
                   <tr>
                       <td align="center">
                           <%= Pagination.getPagination(pageNow,pageCount,rowCount,request.getRequestURI()) %>
                       </td>
                   </tr>
                   </tbody>
               </table>
           </td></tr></table>
	   </td></tr></table>
            

            </div>
        </div>
	<script language="javascript" type="text/javascript">
    $(document).ready(function() {
        $.formValidator.initConfig({ onError: function(msg) { alert(msg) } });
        $("#txt_rno").formValidator({ onshow: "请输入房间编号", onfocus: "房间编号不能为空", oncorrect: "合法" }).InputValidator({ min: 1, onerror: "房间编号不能为空,请确认" });

        $("#txt_floor").formValidator({ onshow: "请输入楼层", onfocus: "楼层不能为空", oncorrect: "合法" }).InputValidator({ min: 1, onerror: "楼层不能为空,请确认" });
        $("#txt_directions").formValidator({ onshow: "请输入朝向", onfocus: "朝向不能为空", oncorrect: "合法" }).InputValidator({ min: 1, onerror: "朝向不能为空,请确认" });
    });
</script>








